#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
using ll = long long;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 100;
const int maxn = 5 + 1e5;

const int mod = 998241383;

ll fxx[maxn]; // f(x, x)
inline void init() {
    fxx[0] = 1;
    for (int i = 1; i < maxn; ++i) fxx[i] = (1LL + i * fxx[i - 1]) % mod;
}

ll val[maxn << 2];
inline void maintain(int u) { val[u] = val[u << 1] * val[u << 1 | 1] % mod; }
void build(int u, int l, int r) {
    if (l == r) {
        val[u] = l;
        return;
    }
    int mid = l + r >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
    maintain(u);
}

ll ask(int u, int l, int r, int s, int t) {
    if (s <= l && r <= t) return val[u];
    int mid = l + r >> 1;
    if (t <= mid) return ask(u << 1, l, mid, s, t);
    if (s > mid) return ask(u << 1 | 1, mid + 1, r, s, t);
    return ask(u << 1, l, mid, s, t) * ask(u << 1 | 1, mid + 1, r, s, t) % mod;
}

inline int f(int x, int y) {
    if (x == y) return fxx[x];
    return ((fxx[x] - ask(1, 1, maxn, x - y, x) * fxx[x - y - 1]) % mod + mod) % mod;
}

int main() {
    init();
    build(1, 1, maxn);
    int Q = rad();
    while (Q--) {
        int n = rad();
        ll ans = 0;
        for (int i = 0; i <= n; ++i) {
            int ai = rad();
            ans += f(i, ai), ans %= mod;
        }
        printf("%d\n", ans);
    }
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}